package org.sharelife.service.impl;

import java.util.Date;

import org.sharelife.dao.IPictureDAO;
import org.sharelife.entity.Picture;
import org.sharelife.service.PictureService;
import org.sharelife.util.DateUtils;
import org.sharelife.util.PageBean;

public class PictureServiceImpl implements PictureService {

	private IPictureDAO iPictureDAO;
	
	@Override
	public boolean add(Picture picture) throws Exception {
		try {
			picture.setUploadTime(DateUtils.formatDate(new Date()));
			Integer integer = iPictureDAO.add(picture);
			if (integer > 0) {
				return true;
			}
		} catch (Exception e) {
			throw e;
		}
		return false;
	}

	@Override
	public PageBean findForPage(int userId, int pageSize, int page)
			throws Exception {
		try {
			return iPictureDAO.findForPage(userId, pageSize, page);
		} catch (Exception e) {
			throw e;
		}
	}
	
	@Override
	public PageBean findAll(int pageSize, int page) throws Exception {
		try {
			return iPictureDAO.findAll(pageSize, page);
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public Picture findById(int id) throws Exception {
		try {
			return iPictureDAO.findById(id);
		} catch (Exception e) {
			throw e;
		}
	}

	public IPictureDAO getiPictureDAO() {
		return iPictureDAO;
	}

	public void setiPictureDAO(IPictureDAO iPictureDAO) {
		this.iPictureDAO = iPictureDAO;
	}

	@Override
	public void delete(int id) throws Exception {
		try {
			iPictureDAO.delete(id);
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public Integer deleteAll() throws Exception {
		try {
			return iPictureDAO.deleteAll();
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public PageBean queryForPage(int pageSize, int page) throws Exception {
		try {
			return iPictureDAO.queryForPage(pageSize, page);
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public PageBean queryByKeyWord(String keyWord, int pageSize, int page)
			throws Exception {
		try {
			return iPictureDAO.queryByKeyWord(keyWord, pageSize, page);
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public PageBean queryByType(String keyWord, int pageSize, int page)
			throws Exception {
		try {
			return iPictureDAO.queryByType(keyWord, pageSize, page);
		} catch (Exception e) {
			throw e;
		}
	}
}
